<template>
  <div>
    <header-index title="收货地址列表" :showTwo="false" />
    <van-address-list
      v-model="chosenAddressId"
      :list="list"
      @select="selectItem"
      :disabled-list="disabledList"
      disabled-text="以下地址超出配送范围"
      default-tag-text="默认"
      @add="onAdd"
      @edit="onEdit"
    ></van-address-list>
  </div>
</template>

<script>
export default {
  data() {
    return {
      chosenAddressId: '1',
      list: [],
      disabledList: [
        {
          id: '3',
          name: '王五',
          tel: '1320000000',
          address: '浙江省杭州市滨江区江南大道 15 号',
        },
      ],
    };
  },
  created() {
    if (localStorage.getItem('addressList')) {
      this.list = JSON.parse(localStorage.getItem('addressList')).map(ele => {
        let addres = ele.addressDetail;
        ele.address = addres;
        delete ele.addressDetail;
        return ele;
      });
    }
  },
  methods: {
    onAdd() {
      this.$router.push('/storeAdress');
    },
    onEdit(_) {
      let info = this.list.find(ele => ele.id == _.id);
      this.$router.push({ path: '/storeAdress', query: { info: JSON.stringify(info) } });
    },
    selectItem(item) {
      localStorage.setItem('currentIndexAdress', JSON.stringify(item));
      this.$router.push('/storeSubmit');
    },
  },
};
</script>

<style scoped></style>
